Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

202
Vistas
Is there a way to render page only after updating infos ? | Ionic - React

I have some troubles with Async functions.
This is not the same as : This question

I'll do my best to explain. So I try to retrieve data from a Firebase Database.
I can upload data to the database without any problem. I can retrieve them too.

"So where is your issue ?" - probably you behind your screen

My issue is showing the data I retrieve from the database. Here is some code :

const [messages,setMessages] = useState<Message[]>([]);

  useIonViewWillEnter(() => {
    const msgs = getMessagesFromDB().then((data)=>{
      setMessages(data);
    });
   setBusy(false)
 });

And on another file :

export const getMessagesFromDB = async () : Promise<Message[]> => {
    const ref = await firebase.default.database().ref('message');
    try{
        ref.on('value', (snapshot) => {
            const data = snapshot.val();
            const current : Message = data['-Mv4-nZYSk9PoE_cwkWw'][0];
           
            setMessages(current);
            return current;
        });
    }catch (e) {
        throw e; 
    }
    return getMessages();
    
};

Here is my issue, if I do a console.log(data), I see my data from the database.
But I use messages on my page, and nothing show up:

 {busy ? <IonSpinner/> :  messages.map(m => <MessageListItem key={m.id} message={m} />)}

Do you know how can I wait for data ?

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda